<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="王劲翔">
    <title>Document</title>
</head>

<body>
    <script>
        const arr4 = [
            { id: 1, name: '茶杯', price: 18 },
            { id: 2, name: '电视机', price: 2000 },
            { id: 3, name: '牙刷', price: 8 },
            { id: 4, name: '电脑', price: 5000 },
        ]

        //冒泡排序
        function sort(arr) {
            let newArr = arr
            newArr.forEach((item, index) =>
                newArr.forEach((item2, index2) => {
                    if (item.price > item2.price) {
                        const temp = newArr[index]
                        newArr[index] = newArr[index2]
                        newArr[index2] = temp
                        return
                    }
                })
            )
            return newArr
        }
        // console.log(sort(arr4));
    </script>
</body>

</html>